/**
 * 全民营销首页
 */
define(function(require, exports, module) {
    var $ = require("jquery");
    var storage = require("storage");
    var angular = require("angular");
    require('global');

    var intro = null;

    function startIntro(){
        var intro = introJs();
        intro.setOptions({
            tooltipClass: 'introjstooltip',
            showStepNumbers:false,
            showBullets:false,
            showButtons:false,
            exitOnEsc: false,
            exitOnOverlayClick: false,
            keyboardNavigation: false,
            steps: [
                {
                    element: '#step2',
                    intro: "<div class='tipscontainer' style='height: 220px;'><img width='367' heihgt='220' src='http://img-dev.myscrmimg.cn/projects/qmyx/public/images/pic/img5.png' /><img class='tipsbtn' data-tipstep='step2' src='http://img-dev.myscrmimg.cn/projects/qmyx/public/images/pic/btn1.png' /></div>",
                    position: 'top'
                },
                {
                    element: '#step3',
                    intro: "<div class='tipscontainer' style='height: 220px;'><img width='367' heihgt='220' src='http://img-dev.myscrmimg.cn/projects/qmyx/public/images/pic/img4.png' /><img class='tipsbtn' data-tipstep='step3' src='http://img-dev.myscrmimg.cn/projects/qmyx/public/images/pic/btn1.png' /></div>",
                    position: 'top'
                }
            ]
        });
        intro.start();
        return intro;
    }
    var app = angular.module('app', []).controller('homeTipLevel',['$scope',function($scope){
        var storageGuide = storage.get('guide-home-tips');
        if(!storageGuide.value) {
            require.async('../intro', function () {
                $scope.tipFirstLevel = !!storageGuide.value;
                if(!storageGuide.value){
                    intro = startIntro();
                    intro.oncomplete(function(){
                        $scope.tipFirstLevel = false;
                        $('.tipContainer').fadeIn();
                    });
                    storage.set({key:'guide-home-tips',value:true,expires:604800000});
                }
                $scope.go=function(){
                    $scope.tipFirstLevel = true;
                    $('.tipContainer').fadeOut();
                }

            })
        }
    }])
    $('body').on('click','.tipsbtn',function(evt){
        intro.nextStep();
        //setTimeout(function(){intro.refresh()},150);
    });

    angular.bootstrap(document, ['app']);

});